<template>
	<view class="container">
		<view class="person-info">
			<view class="icon-container" v-if="safetyEducationInfo.avatar && !loading">
				<preview-image preview-class="avatar" :avatar="safetyEducationInfo.avatar" class="avatar-container"></preview-image>
			</view>
			<view :class="'icon-container ' + (safetyEducationInfo.personType != '10' ? 'orange' : 'green')" v-else-if="!safetyEducationInfo.avatar && !loading">
				<icon type="icon-a-laowurenyuan1x" :size="82" v-if="safetyEducationInfo.personType != '10'" />
				<icon type="icon-a-guanlirenyuan1x" :size="82" v-else />
			</view>
			<view class="icon-container" v-else></view>
			<view class="info-detail-container">
				<view class="info-detail-top">
					<text class="person-name">{{ safetyEducationInfo.name }}</text>
					<text class="work-type">{{ safetyEducationInfo.workTypeName }}</text>
				</view>
				<view class="info-detail-bottom">{{ safetyEducationInfo.orgName }}</view>
			</view>
		</view>
		<scroll-view
			class="scroll-view"
			scroll-y
			:show-scrollbar="false"
			enhanced
			scroll-with-animation
			enable-passive
			fast-deceleration
			:bounces="false"
			refresher-enabled
			:refresher-triggered="isPullRefresh"
			@refresherrefresh="refreshList"
			@scrolltolower="getTrainRecord"
			enable-flex
		>
			<view class="train-record-list" v-if="safetyEducationInfo.recordList.length != 0">
				<view class="train-record" @tap="toTrainDetail" :data-item="item" v-for="(item, index) in safetyEducationInfo.recordList" :key="index">
					<view class="record-title">
						<text class="title">{{ item.trainName }}</text>
						<text class="right-arrow"></text>
					</view>

					<view class="record-content-container">
						<view class="content-item">
							<text class="item-label">培训成绩：</text>
							<text class="item-content">{{ item.score }}</text>
						</view>
						<view class="content-item">
							<text class="item-label">培训总分：</text>
							<text class="item-content">{{ item.fullMark }}</text>
						</view>
					</view>

					<view class="record-content-container">
						<view class="content-item">
							<text class="item-label">培训时间：</text>
							<text class="item-content">{{ item.editTime }}</text>
						</view>
					</view>
				</view>
				<view class="no-more">没有更多了</view>
			</view>
			<view class="no-data-container" v-else>
				<no-data></no-data>
			</view>
		</scroll-view>
	</view>
</template>

<script>
import previewImage from '@/pagesA/components/common/preview-image/preview-image';
import noData from '@/pagesA/components/common/no-data/no-data';
const app = getApp();
export default {
	components: {
		previewImage,
		noData
	},
	data() {
		return {
			loading: true,
			isPullRefresh: false,
			noMore: false
		};
	},
	props: {
		safetyEducationInfo: {
			type: Object,
			default: () => ({})
		}
	},
	methods: {
		refreshList() {
			this.$emit('refreshlist');
		},
		getTrainRecord() {
			if (this.noMore) {
				return;
			}
			this.$emit('getlist');
		},
		toTrainDetail(e) {
			const item = e.currentTarget.dataset.item;
			item.rosterName = this.safetyEducationInfo.name;
			app.globalData.hasTrainDetail = true;
			app.globalData.trainDetailInfo = item;
			uni.navigateTo({
				url: '/pages/roster/trainDetail/trainDetail'
			});
		}
	},
	created: function () {},
	watch: {
		safetyEducationInfo: {
			handler: function (value) {
				if (value.loading) {
					this.loading = false;
				}
				this.setData({
					isPullRefresh: value.isPullRefresh,
					noMore: value.noMore,
					loading: this.loading
				});
			},

			immediate: true,
			deep: true
		}
	}
};
</script>
<style>
.container {
	width: 100vw;
	height: 100%;
	background-color: #f6f7fa;
	display: flex;
	flex-direction: column;
}

.person-info {
	display: flex;
	align-items: center;
	background-color: #fff;
	padding: 32rpx;
	margin-bottom: 24rpx;
}

.person-info .icon-container {
	width: 100rpx;
	height: 100rpx;
	border-radius: 16rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
}

.icon-container .avatar-container {
	width: 100rpx;
	height: 100rpx;
	border-radius: 12rpx;
	background-color: transparent;
}

.icon-container.green {
	background-color: #00c467;
}

.icon-container.orange {
	background-color: #ff9544;
}

.person-info .avatar {
	width: 96rpx;
	height: 96rpx;
	border-radius: 12rpx;
	border: 1rpx solid #c8d1ed;
}

.person-info .info-detail-container {
	margin-left: 24rpx;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
}

.info-detail-container .info-detail-top {
	display: flex;
	align-items: center;
}

.info-detail-top .person-name {
	font-size: 34rpx;
	font-family: PingFangSC-Medium, PingFang SC;
	font-weight: 550;
	color: #1e253f;
	word-break: break-all;
	text-align: justify;
}

.info-detail-top .work-type {
	flex-shrink: 0;
	flex-wrap: wrap;
	max-width: 380rpx;
	background: #eff1f6;
	border-radius: 6rpx;
	padding: 4rpx 16rpx;
	font-size: 24rpx;
	font-family: PingFangSC-Medium, PingFang SC;
	font-weight: 550;
	color: #4b5680;
	margin-left: 16rpx;
	display: flex;
	align-items: center;
	margin-bottom: 4rpx;
	text-align: justify;
	word-break: break-all;
}

.info-detail-bottom {
	font-size: 28rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #949dbf;
}

.scroll-view {
	flex: 1;
	height: 0;
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
}

.train-record-list {
	margin: 0 24rpx;
}

.train-record-list .train-record {
	background: #ffffff;
	border-radius: 16rpx;
	padding: 32rpx;
	margin-bottom: 24rpx;
}

.train-record .record-title {
	display: flex;
	align-items: center;
}

.record-title .title {
	flex: 1;
	min-width: 0;
	text-overflow: ellipsis;
	white-space: nowrap;
	overflow: hidden;
	font-size: 32rpx;
	font-family: PingFangSC-Medium, PingFang SC;
	font-weight: 550;
	color: #1e253f;
	margin-right: 40rpx;
}

.record-title .right-arrow {
	width: 15rpx;
	height: 15rpx;
	border-top: 4rpx solid #949dbf;
	border-right: 4rpx solid #949dbf;
	transform: rotate(45deg);
	margin-left: auto;
}

.train-record .record-content-container {
	margin-top: 24rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.record-content-container .content-item {
	display: flex;
	align-items: center;
	font-size: 28rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
}

.content-item .item-label {
	color: #1e253f;
}

.content-item .item-content {
	color: #4b5680;
}

.no-more {
	font-size: 26rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #949dbf;
	text-align: center;
	padding-bottom: 24rpx;
}

.no-data-container {
	height: 100%;
}
</style>
